package com.ruoyi.carService.controller;

import java.util.List;

import com.ruoyi.system.api.domain.OrdersCountDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.CarOrdersCount;
import com.ruoyi.carService.service.ICarOrdersCountService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 订单统计Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/ordersCount")
public class CarOrdersCountController extends BaseController
{
    @Autowired
    private ICarOrdersCountService carOrdersCountService;

    /**
     * 查询订单统计列表
     */
    @RequiresPermissions("carService:ordersCount:list")
    @GetMapping("/list")
    public TableDataInfo list(CarOrdersCount carOrdersCount)
    {
        startPage();
        List<OrdersCountDto> list = carOrdersCountService.selectCarOrdersCountList(carOrdersCount);
        int weixiuC = 0;
        int baoyangC = 0;
        int xicheC = 0;
        int count = 0;
        for (OrdersCountDto ordersCountDto : list) {
            weixiuC += ordersCountDto.getWeixiu();
            baoyangC += ordersCountDto.getBaoyang();
            xicheC += ordersCountDto.getXiche();
            count += ordersCountDto.getCount();
        }
        list.add(0,new OrdersCountDto("总计", weixiuC, baoyangC, xicheC, count));
        return getDataTable(list);
    }

    /**
     * 导出订单统计列表
     */
   /* @RequiresPermissions("carService:ordersCount:export")
    @Log(title = "订单统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarOrdersCount carOrdersCount)
    {
        List<CarOrdersCount> list = carOrdersCountService.selectCarOrdersCountList(carOrdersCount);
        ExcelUtil<CarOrdersCount> util = new ExcelUtil<CarOrdersCount>(CarOrdersCount.class);
        util.exportExcel(response, list, "订单统计数据");
    }*/

    /**
     * 获取订单统计详细信息
     */
    @RequiresPermissions("carService:ordersCount:query")
    @GetMapping(value = "/{ordId}")
    public AjaxResult getInfo(@PathVariable("ordId") Long ordId)
    {
        return success(carOrdersCountService.selectCarOrdersCountByOrdId(ordId));
    }

    /**
     * 新增订单统计
     */
    @RequiresPermissions("carService:ordersCount:add")
    @Log(title = "订单统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarOrdersCount carOrdersCount)
    {
        return toAjax(carOrdersCountService.insertCarOrdersCount(carOrdersCount));
    }

    /**
     * 修改订单统计
     */
    @RequiresPermissions("carService:ordersCount:edit")
    @Log(title = "订单统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarOrdersCount carOrdersCount)
    {
        return toAjax(carOrdersCountService.updateCarOrdersCount(carOrdersCount));
    }

    /**
     * 删除订单统计
     */
    @RequiresPermissions("carService:ordersCount:remove")
    @Log(title = "订单统计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ordIds}")
    public AjaxResult remove(@PathVariable Long[] ordIds)
    {
        return toAjax(carOrdersCountService.deleteCarOrdersCountByOrdIds(ordIds));
    }
}
